package com.rybbaby.tss.front.tssRightStatistic.dao.imp;

import com.rybbaby.tss.core.web.dao.imp.GenericDao;
import com.rybbaby.tss.front.tssRightStatistic.dao.ITssRightStatisticDao;
import com.rybbaby.tss.front.tssRightStatistic.entity.TssRightStatistic;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @description 权责收入数据库操作实现
 * 
 * @author 雷春琼
 * 
 * @createDate 2017-08-10 上午12:23:36
 */
@Repository
public class TssRightStatisticDaoImp extends GenericDao<TssRightStatistic> implements ITssRightStatisticDao {

    @Override
    public List<TssRightStatistic> findByAttendanceIdAndtype(Object attendanceId, Object type) throws Exception{
        String sql = "select * from tss_right_statistic where attendanceId = ? AND type = ?";
        return this.findListBySql(sql,TssRightStatistic.class,new Object[]{attendanceId,type});
    }

    @Override
    public List<TssRightStatistic> findByReturnPremiumId(String returnPremiumId) throws Exception {
        String sql = "select * from tss_right_statistic where returnPremiumId = ?";
        return this.findListBySql(sql,TssRightStatistic.class,new Object[]{returnPremiumId});
    }

    @Override
    public Map<String, Object> findTodayResponsibility(String adminUserIds) {
        String sql = "select SUM(amount) AS sumAmount from tss_right_statistic where to_days(createTime) = to_days(now()) AND tss_right_statistic.adminUserId in ('"+adminUserIds+"')";
        System.out.println(sql);
        return findOneForJdbc(sql,null);
    }

    @Override
    public Map<String, Object> findMonthResponsibility(String adminUserIds) {
        String sql = "select SUM(amount) AS sumAmount from tss_right_statistic where DATE_FORMAT(createTime, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )AND tss_right_statistic.adminUserId in ('"+adminUserIds+"')";
        System.out.println(sql);
        return findOneForJdbc(sql,null);
    }
}
